script_enemy_main{

let phase=0;
let soundtime=0;

let shot1=0;
let bullet1=[];
let timer1=[];

let character="Hotaru";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=69;
let damagerate=10;
let outfit=6;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshotm3=("\script\SoundEffects\shotm3.wav");
let SEshotb1=("\script\SoundEffects\shotb1.wav");
let SEexplodem1=("\script\SoundEffects\explodem1.wav");

let BG1=("\script\Images\BackgroundLayers\Hotaru1.png");
let BG2=("\script\Images\BackgroundLayers\Hotaru2.png");
let GRboss=("\script\Images\CharacterSprites\Hotaru.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsHotaru1.txt");
	
	LoadSE("\script\SoundEffects\shotm3.wav");
	LoadSE("\script\SoundEffects\shotb1.wav");
	LoadSE("\script\SoundEffects\explodem1.wav");
	
	LoadGraphic("\script\Images\BackgroundLayers\Hotaru1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Hotaru2.png");
	LoadGraphic("\script\Images\CharacterSprites\Hotaru.png");

	SetScore(2500000);
	SetLife(750);
	SetTimer(80);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);

	SetDurableSpellCard;
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(200,200,200,200);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=0; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Pyromania [Flashover]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}


if(frame==240){
let angle=rand(0,360);
	loop(20){
	CreateShot01(GetX,GetY,2,angle,255,0);
	angle+=360/20;
	}
PlaySE(SEshotm3);
}

if(frame==60){
let angle=rand(0,360);
let speed=rand(0,360);
	loop(20+phase){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,cx+330*cos(angle),cy+330*sin(angle));
	Obj_SetAngle(shot1,angle+180+rand(-20,20));
	Obj_SetSpeed(shot1,1.5+0.5*cos(speed));
	ObjShot_SetGraphic(shot1,134);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=rand_int(0,10);
	angle+=360/(20+phase);
	speed+=rand_int(30,60);
	}
}

if(frame==60 || frame==66 || frame==72){
	PlaySE(SEshotb1);
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i);
	i--;
	}
	else{
		if(timer1[i]==195){ ObjShot_SetGraphic(bullet1[i],133); }
		if(timer1[i]==210){
		let shot2=0;
			loop(12){
			CreateShotA(shot2,Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0);
			SetShotDataA(shot2,0,rand(5,3),rand(0,360),0,-0.15,rand(0.8,1.2),26);
			FireShot(shot2);
			}		
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ soundtime=5; }
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(soundtime==1){ PlaySE(SEexplodem1); }
if(soundtime>0){ soundtime--; }
if(frame==330){ if(phase<16){ phase+=2; } frame=0; }


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0-time,300,300-time);
	SetGraphicScale(2+0.3*cos(time),2-0.3*cos(time));
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(180,180,180);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0+time,0-time/2,300+time,300-time/2);
	SetGraphicScale(2,2);
	SetTexture(BG2);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	if(GotSpellCardBonus){ SetCommonData("LastTrumpCard",2); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}